package com.chixing.ih.module.admin.mapper.Provider;

import com.chixing.ih.util.EmptyUtil;
import org.apache.ibatis.jdbc.SQL;

public class AdminTaskMapperProvider {

    //0-待审核;1-已审核
    public String getPendingTasks(String keyword) {
        return new SQL() {{
            SELECT("*");
            FROM("tbl_task");
            if (!EmptyUtil.isEmpty(keyword)) {
                WHERE("task_title LIKE CONCAT('%',#{keyword},'%')");
            }
            AND();
            WHERE("type_status = 0");
            ORDER_BY("update_time DESC");
        }}.toString();
    }

    public String getAuditedTasks(String keyword) {
        return new SQL() {{
            SELECT("*");
            FROM("tbl_task");
            if (!EmptyUtil.isEmpty(keyword)) {
                WHERE("task_title LIKE CONCAT('%',#{keyword},'%')");
            }
            AND();
            WHERE("type_status = 1 AND is_deleted=0");
            ORDER_BY("update_time DESC");
        }}.toString();
    }

    public String getRefusedTasks(String keyword) {
        return new SQL() {{
            SELECT("*");
            FROM("tbl_task");
            if (!EmptyUtil.isEmpty(keyword)) {
                WHERE("task_title LIKE CONCAT('%',#{keyword},'%')");
            }
            AND();
            WHERE("type_status = 2");
            ORDER_BY("update_time DESC");
        }}.toString();
    }


    public String applicationApproved(Integer id) {
        return new SQL() {{
            UPDATE("tbl_task");
            SET("type_status = 1");
            WHERE("id = #{id}");
        }}.toString();
    }

    public String rejectApplication(Integer id) {
        return new SQL() {{
            UPDATE("tbl_task");
            SET("type_status = 2");
            WHERE("id = #{id}");
        }}.toString();
    }

    public String resetApplication(Integer id) {
        return new SQL() {{
            UPDATE("tbl_task");
            SET("type_status = 0");
            WHERE("id = #{id}");
        }}.toString();
    }


}
